
#include "stdafx.h"
#include "BaseSocket.h"
#ifndef _BIDCONTROL_
#include "Utility.h"
#else
#include "..\\..\\BidServer\\Utility.h"
#endif

CBaseSocket::CBaseSocket()
{
	hThread = nullptr; sock = INVALID_SOCKET; sockAvailable = false;
}

CBaseSocket::~CBaseSocket()
{
}

DWORD WINAPI StartThread_BaseSocket(LPVOID p)
{
	CBaseSocket *pCaller = (CBaseSocket*)p; if (!pCaller) return -1;
	pCaller->ProcThread();
	return 0;
}
bool CBaseSocket::Start()
{
	if (IsRunning()) return false;
	hThread = CreateThread(NULL, 0, StartThread_BaseSocket, this, 0, NULL);
	return !!hThread;
}

void CBaseSocket::Stop(bool wait)
{
	if (!IsRunning()) return;
	stopThread = true;
	if (IsRunning() && wait) while (IsRunning()) Sleep(10);
}

bool CBaseSocket::IsRunning()
{
	return CheckThread(hThread);
}
